const express = require("express");
const router = express.Router();
const axios = require("axios");
let baseUrl = "http://localhost:5008/api/user";

// 用户登录
router.post("/login", async (req, res, next) => {
  console.log(req.body);
  const { data } = await axios.post(`${baseUrl}/login`, {
    account: req.body.account,
    password: req.body.password,
  }, {
    headers: req.headers
  }
  );
  // console.log("result from server: ", data);
  res.send(data);
  next();
});

// 更新用户信息
router.post("/update", async (req, res, next) => {
  console.log(req.body);
  const { data } = await axios.post(`${baseUrl}/update`, req.body, {
    headers: req.headers
  }
  );
  // console.log("result from server: ", data);
  res.send(data);
  next();
});

router.post("/getOperationLog", async (req, res, next) => {
  console.log(req.body);
  const { data } = await axios.post(`${baseUrl}/getOperationLog`, req.body, {
    headers: req.headers
  }
  );
  // console.log("result from server: ", data);
  res.send(data);
  next();
});


// 获取所有用户
router.get("/getAllUser", async (req, res, next) => {
  console.log(req);
  const { data } = await axios.get(`${baseUrl}/getAllUser`, {
    headers: req.headers
  }
  );
  // console.log("result from server: ", data);
  res.send(data);
  next();
});

router.get("/getAtmList", async (req, res, next) => {
  const { data } = await axios.get(`${baseUrl}/getAtmList`, {
    params: {
      userId: req.query.userId
    },
    headers: req.headers
  }
  );
  // console.log("result from server: ", data);
  res.send(data);
  next();
});

module.exports = router;